//index.js
//获取应用实例
const app = getApp()
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');
Page({
	data: {
		windowWidth: app.systemInfo.windowWidth,
		windowHeight: app.systemInfo.windowHeight,
		pixelRatio: app.systemInfo.pixelRatio,
		orderList:[],
		pageNum:1,//当前页
		total:0,//总条数
		customerId:""
	},
	//事件处理函数
	cancelCourse:function(e){
		let _this = this;
		api.orderWriteOff({
			data: {
				id: e.currentTarget.dataset.id,
			},
			success: function(res) {
				if(res.data.code == 0) {
					_this.getOrderList();
				}else{
					
				}
			},
		});
	},
	onShow: function() {
		let _this = this;
		wx.getStorage({
		 	key: 'customerId',
		  	success: function(res) {
		  		_this.setData({
					customerId: res.data,
				});
		      	_this.getOrderList();
		  	} 
		})
	},
	getOrderList:function(){
		let _this = this;
		api.getOrderList({
			data: {
				orderStatus: "1",
				customerId: _this.data.customerId,
				pageSize: "20",
				pageNum: _this.data.pageNum,
			},
			success: function(res) {
				if(res.data.code == 0) {
					res.data.obj.rows.forEach(function(item) {
						if(item.courseTime.startTime != null) {
							item.courseTime.startTime = util.formatEndTime(new Date(item.courseTime.startTime));
						}
					});
					_this.setData({
						orderList: res.data.obj.rows,
						total:res.data.obj.total
					});
				}
			},
		});
	},
	loadMore:function(){
		let _this = this;
		if(this.data.total > this.data.pageNum * 20){
			setTimeout(function(){
				_this.setData({
					pageNum: _this.data.pageNum + 1
				});
				_this.getOrderList();
			},500);
		}else{
			console.log(this.data.pageNum)
		}
	}

})